package dbhandler;

import evthandler.EventMessage;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author Casper, Dennis, Jackie, Jakob
 * @version 1.00
 */
public class Login{

    private String userName;
    private String fullName;
    private String userPass;
    private UserLevel userLvl;

    public Login() {
        
    }
    /**
     *
     * @param userName
     */
    public Login(String userName) {
        this.userName = userName;
        int levelNo = 0;
        try {
            ResultSet rs = DbCon.getInstance().executeQuery("SELECT * FROM login WHERE userName='" + userName + "'");
            while (rs.next()) {
                fullName = rs.getString("fullName");
                userPass = rs.getString("userPass");
                levelNo = rs.getInt("levelNo");
            }
        } catch (SQLException ex) {
            new EventMessage("SQL error in Login", "There was an error performing the sql inquery\n").showException(ex);
        }
        userLvl = new UserLevel(levelNo);
    }

    public boolean exists(String userName) {
        boolean exists = false;
        try {
            ResultSet rs = DbCon.getInstance().executeQuery("SELECT count(userName) FROM login WHERE userName='" + userName + "'");
            while (rs.next()) {
                if (rs.getInt(1) > 0) {
                    exists = true;
                }
            }
        } catch (SQLException ex) {
            new EventMessage("SQL error in Login", "There was an error performing the sql inquery\n").showException(ex);
        }
        return exists;
    }

    /**
     *
     * @return
     */
    public UserLevel getUserLvl() {
        return userLvl;
    }

    /**
     *
     * @return
     */
    public String getUserName() {
        return userName;
    }

    /**
     *
     * @return
     */
    public String getFullName() {
        return fullName;
    }

    /**
     *
     * @return
     */
    public String getUserPass() {
        return userPass;
    }

    /**
     *
     * @return
     */
    public UserLevel getUserLevel() {
        return userLvl;
    }
}
